package com.bougaga.samplespringcloud.kafka.provider.sender;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.support.MessageBuilder;

import com.bougaga.samplespringcloud.kafka.provider.pipeline.Source;

@EnableBinding(Source.class)
public class KafkaSender {
	private final Logger logger = LoggerFactory.getLogger(KafkaSender.class);

	@Autowired
	private Source source;

	public void sendMessage(String message) {
		try {
			logger.info("发送消息：{}",message);
			source.output1().send(MessageBuilder.withPayload("message: " + message).build());
		} catch (Exception e) {
			logger.info("消息发送失败，原因：" + e);
			e.printStackTrace();
		}
	}
}
